import { MongoClient } from "mongodb";
import assert from "assert";
import fmt from "./date-fmt.js";

const uri =
  "mongodb://admin123:admin123@81.68.239.226:27017/?maxPoolSize=20&writeConcern=majority&authSource=admin";

const client = new MongoClient(uri);

async function connect() {
  try {
    client.connect();
    const db = client.db("test");

    // await db.createCollection("users");
    db.collection("users")
      .insertOne({
        name: "xinyang3",
        pwd: "xinyang3",
        type: "manager",
        date: fmt(new Date(), "yyyy-MM-dd mm:hh:ss"),
        createUser: "root",
        updateUser: "root",
        state: "1",
      })
      .then(() => {
        client.close();
        console.log("mongo is closed successfully.");
      });

    console.log("mongo connect successfully to server.");
  } catch (error) {
    console.log(error);
  } finally {
  }
}

export default connect;
